#include<iostream>
#include<algorithm>
#include<cstring>
#include<deque>
#define x first
#define y second

using namespace std;
typedef pair<int, int> PII;
const int N = 1e3 + 10;

int map[N][N];
int dis[N][N];
bool vis[N][N];
int vx[] = { 0,1,0,-1 };
int vy[] = { 1,0,-1,0 };

int bfs(int sx, int sy)
{
	deque<PII> q;
	q.push_back({ sx,sy });
	memset(dis, 0x3f3f, sizeof dis);
	dis[sx][sy] = 0;
	while (q.size())
	{
		auto a = q.front();
		q.pop_front();
		if (vis[a.x][a.y])
			continue;
		vis[a.x][a.y] = true;
		if(!a.x&&!a.y)
		    break;
		for (int i = 0; i < 4; i++)
		{
			int u = a.x + vx[i];
			int v = a.y + vy[i];
			if (u >= 0 && v >= 0 && u < N && v < N)
			{
				int w = 0;
				if (map[u][v] == 1)
					w = 1;
				if (dis[u][v] > dis[a.x][a.y] + w)
				{
					dis[u][v] = dis[a.x][a.y] + w;
					if (map[u][v] == 0)
						q.push_front({ u,v });
					else
						q.push_back({ u,v });
				}
			}
		}
	}
	return dis[0][0];
}
int main()
{
	int sx, sy, n;
	cin >> n >> sx >> sy;
	while (n--)
	{
		int u, v;
		cin >> u >> v;
		map[u][v] = 1;
	}
	cout << bfs(sx, sy) << endl;
	return 0;
}
